package ch.sfug.anim.tween.property {
	import flash.display.DisplayObject;
	
	import ch.sfug.anim.tween.CompositeTween;	

	/**
	 * @author marcel
	 */
	public class Scaler extends CompositeTween {

		public function Scaler( d:DisplayObject, dur:uint ) {
			tween = new PropertyTween( d, dur );
		}
		
		public function scaleToX( x:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj[ "scaleX" ] = { to: x, easing: ease };
			PropertyTween( tween ).tween(obj);
		}

		public function scaleToY( y:Number, ease:Function = null ):void {
			var obj:Object 	= new Object();
			obj[ "scaleY" ] = { to: y, easing: ease };
			PropertyTween( tween ).tween(obj);
		}
		
		public function scaleTo( x:Number, y:Number, easeXBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(x) ) obj[ "scaleX" ] = { to: x, easing:easeXBoth };
			if( !isNaN(y) ) obj[ "scaleY" ] = { to: y, easing:( easeY == null ) ? easeXBoth : easeY };
			PropertyTween( tween ).tween(obj);
		}
		
		public function scaleFromTo( xfrom:Number, xto:Number, yfrom:Number, yto:Number, easeXBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xfrom) && !isNaN(xto) ) obj[ "scaleX" ] = { from: xfrom, to: xto, easing:easeXBoth };
			if( !isNaN(yfrom) && !isNaN(yto) ) obj[ "scaleY" ] = { from: yfrom, to: yto, easing:( easeY == null ) ? easeXBoth : easeY };
			PropertyTween( tween ).tween(obj);
		}
		
		
		public function scaleFromXToX( xfrom:Number, xto:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xfrom) && !isNaN(xto) ) obj[ "scaleX" ] 	 = { from: xfrom, to: xto, easing:ease };
			PropertyTween( tween ).tween(obj);
		}
		
		public function scaleFromYToY( yfrom:Number, yto:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(yfrom) && !isNaN(yto) ) obj[ "scaleY" ] 	 = { from: yfrom, to: yto, easing:ease };
			PropertyTween( tween ).tween(obj);
		}
		
	
		public function scaleXBy( xamount:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xamount) && xamount != 0 ) 	obj[ "scaleX" ] = { by: xamount, easing:ease };
			PropertyTween( tween ).tween(obj);
		}
		
		public function scaleYBy( yamount:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(yamount) && yamount != 0 ) 	obj[ "scaleY" ] = { by: yamount, easing:ease };
			PropertyTween( tween ).tween(obj);
		}
		
		public function scaleBy( xamount:Number, yamount:Number, easeXBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xamount) && xamount != 0 ) obj[ "scaleX" ] = { by: xamount, easing:easeXBoth };
			if( !isNaN(yamount) && yamount != 0 ) obj[ "scaleY" ] = { by: yamount, easing:( easeY == null ) ? easeXBoth : easeY };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * sets the target the fade
		 */
		public function set target( d:DisplayObject ):void {
			tween.target = d;
		}
				/**
		 * returns the display object that fades
		 */
		public function get target(  ):DisplayObject {
			return DisplayObject(tween.target);
		}
				/**
		 * sets the duration of the Resizer
		 */
		public function set duration( n:Number ):void {
			tween.duration = n;
		}
				/**
		 * returns the duration of the Resizer
		 */
		public function get duration( ):Number {
			return tween.duration;
		}
				/**
		 * applies new x/y position
		 */
		public function apply( new_width:Number = NaN, new_height:Number = NaN ):void {
			var obj:Object = new Object();
			if( !isNaN(new_width) )  obj["width"] 	= new_width;
			if( !isNaN(new_height) ) obj["height"] 	= new_height;
			PropertyTween( tween ).apply(obj);
		}
	}
}
